clear all
set more off
cap log close
cd "${master_dir}"
log using "${log_dir}/1d-IdentifyRegularPingers.log", replace
***************************************************************************************************
* 
* Program: 1d-IdentifyRegularPingers.do
* Purpose: Identify the number of unique hours that each phone pings on Election Day
*          Will use this to identify a filter based on being a "regular pinger"
* Files Used:
*     1. Pings_all_days.dta
*     2. PollingPlaces2016_w_TimeZones_and_Buildings.dta
* Files Created:
*     1. 1d-IdentifyRegularPingers.log
*     2. likelyvoters.dta
*     3. likelyvoters_rad10.dta - likelyvoters_rad100.dta
*
***************************************************************************************************

* Start with all cellphone data on election day 2016
* For each unique device, generate the number of unique hours that they received a ping on that day
* Save a file with this summary stat, by device, so it can be merged into the other files

use "J:\voting files\11_16_All_SortGH_Day8.dta", clear

keep utc_timestamp ID_11_16

* Generate a stata date variables using the utc timestamp for each ping
gen double greenwich_date_sec = utc_timestamp*1000 + mdyhms(1,1,1970,0,0,0)
format greenwich_date_sec %tC
		
gen hour = hh(greenwich_date_sec)
egen hourIDtag = tag(ID_11_16 hour)
bys ID: egen uniquepinghours = sum(hourIDtag)
collapse (mean) uniquepinghours, by(ID_11_16)
save "$data_dir/IdentifiedRegularPingers.dta", replace

log close
stop